package com.zgscwjm.taobaphelper;

import android.app.Application;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

import com.zgscwjm.taobaphelper.exutils.StringUtils;

import static android.content.pm.PackageManager.GET_META_DATA;

/**
 * 对应BaseApplication
 * Created by zgscwjm on 17-2-27.
 */
public class BaseApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        if (StringUtils.isEmpty(BaseConfig.baseUrl)){
            return;
        }
        ApplicationInfo applicationInfo;
            try {
                // FIXME: 17-2-27 这里的flags 原本是128
                applicationInfo = getPackageManager().getApplicationInfo(getPackageName(),GET_META_DATA);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
                applicationInfo = null;
            }
            if (applicationInfo!=null){
                String string = applicationInfo.metaData.getString("UMENG_CHANNEL");
                if (!StringUtils.isEmpty(string)){
                    BaseConfig.baseUrl = "http://"+string+"/";
                }
            }
    }
}
